// pages/message/message.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    messageArray: []
  },

  onLoad: function (options) {

    var that = this;
    
    var result = [];
    var messageData = JSON.parse(options.message);

    for (var i = 0; i < messageData.alramMessage.length; i++) {
      var obj = messageData.alramMessage[i];
      result.push({
        "messageName": obj.alarmTypeName,
        "messageContent": obj.alarmCodeName,
        "messageTime": obj.dtarStarTime
      });
    }

    for (var i = 0; i < messageData.wxAppMessage.length; i++) {
      var obj = messageData.wxAppMessage[i];
      result.push({
        "messageName": obj.messageName,
        "messageContent": obj.messageContent,
        "messageTime": obj.messageTime
      });
    }

    //时间倒叙
    var rows = result;
    rows.sort(function (a, b) {
      return Date.parse(b.messageTime) - Date.parse(a.messageTime);
    });

    that.setData({
      messageArray: rows
    })

  },

  showDetail: function (e){
    
    wx.navigateTo({ //跳转到详情
      url: '/pages/messageDetail/messageDetail?detail=' + JSON.stringify(e.currentTarget.dataset.index)
    })
  }

})